package com.nan.gbd.library.codec.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by jiaqing on 2018/1/4.
 */

public class NetworkUtil {

    /**
     * 网络是否可用
     * @return
     */
    public static boolean hasNetwork(Context mContext) {
        ConnectivityManager manager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (manager == null) {
            return false;
        }
        NetworkInfo networkinfo = manager.getActiveNetworkInfo();
        return (networkinfo != null && networkinfo.isAvailable());
    }

    /**
     * 当前网络是否是wifi
     * @return
     */
    public static boolean isWifiNetwork(Context mContext) {
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null
                && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }

        return false;
    }



}
